package com.example;

import com.example.config.SpringConfig;
import com.example.config.SpringConfig2;
import com.example.entity.Person;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.Map;

public class MainTest1 {
    @Test
    public void main1() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);

        //容器中有两个bean类型相同执行下面这句会抛出异常
        //System.out.println(context.getBean(Person.class));

        //某一类型的所有bean的标识
        String[] names = context.getBeanNamesForType(Person.class);

        //所有定义在容器中的bean的标识
        String[] definitionNames = context.getBeanDefinitionNames();


        Object user = context.getBean("user");
        Object user1 = context.getBean("user");

        Object o1 = context.getBean("person1");
        Object o2 = context.getBean("person1");

    }

    @Test
    public void main2() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig2.class);

        ConfigurableEnvironment environment = context.getEnvironment();
        String property = environment.getProperty("os.name");

        String[] definitionNames = context.getBeanDefinitionNames();
        Map<String, Person> beansOfType = context.getBeansOfType(Person.class);
    }
}




